#include <vector>
#include <iostream>
using std::cout;
using std::endl;
using std::vector;

void test0(){
    vector<int> numbers(10);

    //使用迭代器方式进行遍历
    auto it = numbers.begin();
    /* vector<int>::iterator it = numbers.begin(); */
    while(it != numbers.end()){
        cout << *it << " ";
        ++it;
    }
    cout << endl;

    //为空就返回1，非空返回0
    vector<int> numbers2;
    cout << "is numbers2 empty? " << numbers2.empty() << endl;

}
void displayVector(const vector<int> & v){
    cout << "v's size:" << v.size() << endl;
    cout << "v'capacity:" << v.capacity() << endl;
}

void test1(){
    vector<int> numbers;
    displayVector(numbers);

    numbers.push_back(1);
    displayVector(numbers);

    numbers.push_back(1);
    displayVector(numbers);
    numbers.push_back(1);
    displayVector(numbers);
    numbers.push_back(1);
    displayVector(numbers);
    numbers.push_back(1);
    displayVector(numbers);
    numbers.push_back(1);
    displayVector(numbers);
    numbers.push_back(1);
    displayVector(numbers);
    numbers.push_back(1);
    displayVector(numbers);
    numbers.push_back(1);
    displayVector(numbers);

#if 0
    cout << sizeof(long) << endl;
    cout << sizeof(numbers) << endl;

    cout << "&numbers:" << &numbers << endl;
    cout << "&numbers[0]:" << &numbers[0] << endl;
    /* cout << numbers.begin() << endl;//error */
    cout << &*numbers.begin() << endl;
    /* printf("%p\n",numbers.begin()); */
#endif

    cout << "释放多余的空间" << endl;
    numbers.shrink_to_fit();
    displayVector(numbers);

    cout << "清空所有元素" << endl;
    numbers.clear();
    displayVector(numbers);
    numbers.shrink_to_fit();
    displayVector(numbers);
}

void test2(){
    vector<int> numbers;
    numbers.reserve(10);
    displayVector(numbers);

}

int main(void){
    /* test0(); */
    /* test1(); */
    test2();
    return 0;
}
